<!DOCTYPE html>
<body>
<script src='../../resources/js-test.js'></script>
<script>
description('document.write inside onunload handler should not cause crash.');
jsTestIsAsync = true;

window.onload = function() {
    var iframe = document.createElement('iframe');
    var loadCount = 0;
    iframe.addEventListener('load', function() {
        ++ loadCount;
        if (loadCount == 1) {
            debug('iframe loaded successfully');
            iframe.src = 'about:blank';
        }
    });
    window.addEventListener('message', function() {
        shouldBe('"Done"', 'event.data');
        debug('iframe unloaded successfully');
        document.body.removeChild(iframe);
        finishJSTest();
    });

    iframe.src = 'resources/document-open-in-unload-inner.html';
    document.body.appendChild(iframe);
}
</script>
<p>Test passes if it doesn't crash</p>
</body>
